<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('优惠券列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>优惠券名称：</label>
                                <input type="text" name="title"/>
                            </li>
                            <li>
                                <label>类型：</label>
                                <select name="type">
                                    <option value="">所有</option>
                                    <option value="1">满减券</option>
                                    <option value="2">叠加满减券</option>
                                    <option value="3">无门槛券</option>
                                </select>
                            </li>
                            <li>
                                <label>使用开始时间：</label>
                                <input type="text" class="time-input" placeholder="请选择使用开始时间" name="validStartTime"/>
                            </li>
                            <li>
                                <label>使用结束时间：</label>
                                <input type="text" class="time-input" placeholder="请选择使用结束时间" name="validEndTime"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status">
                                    <option value="">所有</option>
                                    <option value="1">正常</option>
                                    <option value="2">不能使用</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="coupon:coupon:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="coupon:coupon:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="coupon:coupon:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="coupon:coupon:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('coupon:coupon:edit')}]];
        var removeFlag = [[${@permission.hasPermi('coupon:coupon:remove')}]];
        var prefix = ctx + "coupon/coupon";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "优惠券",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '优惠券id',
                    visible: false
                },
                {
                    field: 'title',
                    title: '优惠券名称'
                },
                {
                    field: 'icon',
                    title: '图片'
                },
                {
                    field: 'type',
                    title: '类型',
                    formatter: function(value, row, index) {
                    if(1 == value){
                        return "满减券";
                    } else if (2 == value) {
                        return "叠加满减券"
                    } else if (3 == value) {
                        return "无门槛券"
                    }
            }
                },
                {
                    field: 'withAmount',
                    title: '满多少金额'
                },
                {
                    field: 'amount',
                    title: '优惠券金额'
                },
                {
                    field: 'quota',
                    title: '发券数量'
                },
                {
                    field: 'takeCount',
                    title: '已领取数量'
                },
                {
                    field: 'usedCount',
                    title: '已使用数量'
                },
                {
                    field: 'startTime',
                    title: '发放开始时间'
                },
                {
                    field: 'endTime',
                    title: '发放结束时间'
                },
                {
                    field: 'validType',
                    title: '时效',
                    formatter: function(value, row, index) {
                        if(1==value){
                            return "绝对时效";
                        } else if(2==value){
                            return "相对时效";
                        }
                    }
                },
                {
                    field: 'validStartTime',
                    title: '使用开始时间'
                },
                {
                    field: 'validEndTime',
                    title: '使用结束时间'
                },
                {
                    field: 'validDays',
                    title: '自领取之日起有效天数'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        if(1==value){
                            return "正常";
                        } else if (2==value){
                            return "不能使用"
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>